<?php

class event_racechoice
{
	var $division_id = 0;
	var $event_id = 0;
	var $race_id;
		
	var $select_results_options = '';
        var $count = 0;
	
	function event_racechoice($event_id)
	{
		$this->event_id = $event_id;
		if(isset($_GET['race']))
		{
			$race = split('-',$_GET['race']);
			$this->division_id = $race[0];
			$this->race_id = $race[1];
		}
		
		global $db, $lang;
		$q = 'SELECT DISTINCT r_race, d_id, d_title, e_id, c_title FROM ' . 
				RACERESULTS_TABLE . ', ' . CHAMPSIGNUPS_TABLE . ' ,' . EVENTS_TABLE . ', ' . DIVISIONS_TABLE .  ', ' . CHAMPIONSHIPS_TABLE . 
				' WHERE cs_div = d_id AND r_driver = cs_driver AND c_id = cs_champ AND 
						cs_champ = e_championship AND e_id = r_event AND e_id = ' . $event_id .
				' ORDER BY d_order ASC, r_race ASC';

		$res = $db->sql_query($q);
		
		$matched = false;
		$t_div = 0;
		$t_race = 0;
		
		while ($row = $db->sql_fetchrow($res))
		{
                        $this->count++;
			$division = '';
			if($row['c_title'] != $row['d_title'])
			{
				$division = $row['d_title'] . ' ';
			}
			
			if($this->division_id == $row['d_id'] && $this->race_id == $row['r_race'])
			{
				$this->select_results_options .= '<option value="' . $row['d_id'] . '-' . $row['r_race'] . '" SELECTED>' . 
													$division . $lang['ResultsRace'] . ' ' . $row['r_race'] .
													'</option>';
				$matched = true;
			}
			else if($this->division_id  == 0 && $this->event_id == 0)
			{
				$this->division_id = $row['d_id'];
				$this->race_id = $row['r_race'];
				$this->select_results_options .= '<option value="' . $row['d_id'] . '-' . $row['r_race'] . '" SELECTED>' . 
													$division . $lang['ResultsRace'] . ' ' . $row['r_race'] .
													'</option>';
				$matched = true;
			}
			else
			{
				$this->select_results_options .= '<option value="' . $row['d_id'] . '-' . $row['r_race'] . '">' . 
													$division . $lang['ResultsRace'] . ' ' . $row['r_race'] .
													'</option>';
				if($t_race == 0 && $t_div == 0)
				{
					$t_div = $row['d_id'];
					$t_race = $row['r_race'];
				}
			}
		}
		
		if(!$matched)
		{
			$this->division_id = $t_div;
			$this->race_id = $t_race;
		}
	}
	
	function getRaceID()
	{
		return $this->race_id;
	}
	
	function getDivisionID()
	{
		return $this->division_id;
	}
	
	function render()
	{
            if($this->count > 1)
            {
		global $lang, $skin_dir;
		$id = $this->event_id;
		$action = 'events';
		$select_results_options = formatFormOutput($this->select_results_options);
		include $skin_dir . 'tpl/resultsChoice.tpl';
            }
	}
}

class champ_racechoice
{
	var $division_id = 0;
	var $event_id = 0;
	var $champ_id = 0;
	var $track_logo = '';
	var $race_id;
        var $count = 0;
		
	var $select_results_options = '';
	
	function champ_racechoice($champ_id)
	{
		$this->champ_id = $champ_id;
		if(isset($_GET['race']))
		{
			$race = split('-',$_GET['race']);
			$this->event_id = $race[0];
			$this->division_id = $race[1];
			$this->race_id = $race[2];
		}
		
		global $db, $lang;
		$q = 'SELECT DISTINCT e_id, r_race, d_id, d_title, t_fullTitle, e_title, c_title, t_logoThmb, ' .
  				'(SELECT ed_date FROM '. EVENTDATES_TABLE .' WHERE ed_event = e_id ORDER BY ed_date ASC LIMIT 0,1) as ed_date ' .
				'FROM ' . TRACKS_TABLE . ', ' . RACERESULTS_TABLE . ', ' . CHAMPSIGNUPS_TABLE . 
				', ' . EVENTS_TABLE . ', ' . DIVISIONS_TABLE . ', ' . CHAMPIONSHIPS_TABLE .
				' WHERE e_track = t_id AND cs_div = d_id AND r_driver = cs_driver AND c_id = cs_champ AND ' . 
				'cs_champ = e_championship AND e_id = r_event AND cs_champ = ' . $champ_id .
				' ORDER BY d_order ASC, ed_date ASC, r_race ASC';

		$res = $db->sql_query($q);
		
		$matched = false;
		$t_div = 0;
		$t_race = 0;
		$t_event = 0;
		$t_track = 0;
		
		while ($row = $db->sql_fetchrow($res))
		{
                        $this->count++;
                    	if($this->event_id == $row['e_id'] && $this->division_id == $row['d_id'] && $this->race_id == $row['r_race'])
			{
				$row['d_title'] = $row['d_title'] == $row['c_title'] ? ' - ' : ' - ' . $row['d_title'] . ' ';
				$this->track_logo = $row['t_logoThmb'];
				$this->select_results_options .= '<option value="' . $row['e_id'] . '-' . $row['d_id'] . '-' . $row['r_race'] . '" SELECTED>' . 
													$row['e_title'] . ': ' . $row['t_fullTitle'] . $row['d_title']  . 
													$lang['ResultsRace'] . ' ' . $row['r_race'] . '</option>';
				$matched = true;
			}
			else if($this->division_id  == 0 && $this->event_id == 0)
			{
				$this->division_id = $row['d_id'];
				$this->race_id = $row['r_race'];
				$this->event_id = $row['e_id'];
				$this->track_logo = $row['t_logoThmb'];
				$row['d_title'] = $row['d_title'] == $row['c_title'] ? ' - ' : ' - '  . $row['d_title'] . ' ';
				$this->select_results_options .= '<option value="' . $row['e_id'] . '-' . $row['d_id'] . '-' . $row['r_race'] . '" SELECTED>' . 
													$row['e_title'] . ': ' . $row['t_fullTitle'] . $row['d_title'] . 
													$lang['ResultsRace'] . ' ' . $row['r_race'] . '</option>';
				$matched = true;
			}
			else
			{
				$row['d_title'] = $row['d_title'] == $row['c_title'] ? ' - ' : ' - '  . $row['d_title'] . ' ';
				$this->select_results_options .= '<option value="' . $row['e_id'] . '-' . $row['d_id'] . '-' . $row['r_race'] . '">' . 
													$row['e_title'] . ': ' . $row['t_fullTitle'] . $row['d_title'] . 
													$lang['ResultsRace'] . ' ' . $row['r_race'] . '</option>';
				if($t_race == 0 && $t_div == 0)
				{
					$t_div = $row['d_id'];
					$t_race = $row['r_race'];
					$t_track = $row['t_logoThmb'];
				}
			}
		}
		
		if(!$matched)
		{
			$this->division_id = $t_div;
			$this->race_id = $t_race;
			$this->track_logo = $t_track;
		}
	}
	
	function getRaceID()
	{
		return $this->race_id;
	}
	
	function getDivisionID()
	{
		return $this->division_id;
	}
	
	function getEventID()
	{
		return $this->event_id;
	}
	
	function getTrackLogo()
	{
		return $this->track_logo;
	}
	
	function render()
	{
            if($this->count > 1)
            {
		global $lang, $skin_dir;
		$id = $this->champ_id;
		$action = 'championships';
		$select_results_options = formatFormOutput($this->select_results_options);
		include $skin_dir . 'tpl/resultsChoice.tpl';
            }
	}
}

class event_results
{
	var $records = Array();
	var $url, $replay, $rfreport, $incident;
	
	function event_results($event_id, $division_id, $race_id, $url)
	{
		global $db, $lang, $properties;
		$champ_id = 0;
		if(substr($url,0,1) == 'e')
			$this->url = $url . '&race=' . $division_id . '-'. $race_id;
		else
			$this->url = $url . '&race=' . $event_id . '-'. $division_id . '-'. $race_id;
		
		include_once('includes/page_header.php');
		
		$filter = '';
		if(isset($_GET['order']))
		{
			if($_GET['order'] == 2)
			{
				$filter = 'r_racelaps DESC, r_raceposition ASC';
			}
			else if($_GET['order'] == 3)
			{
				$filter = 'r_racetime ASC, r_racelaps DESC';
			}
			else if($_GET['order'] == 4)
			{
				$filter = 'r_pitstops DESC';
			}
			else if($_GET['order'] == 5)
			{
				$filter = 'r_lapsled DESC';
			}
			else if($_GET['order'] == 6)
			{
				$filter = 'r_qualifyingrank ASC';
			}
			else if($_GET['order'] == 7)
			{
				$filter = 'r_fastestlap_rank ASC';
			}
			else if($_GET['order'] == 8)
			{
				$filter = 'r_points DESC';
			}
			else if($_GET['order'] == 9)
			{
				$filter = 'r_weight DESC';
			}
			else
			{
				$filter = 'r_raceposition ASC';
			}
		}
		else
		{
			$filter = 'r_raceposition ASC';
		}
		$q = 'SELECT e_championship, 
					 (DATE_ADD(ed_resultsPosted, INTERVAL ' . $properties['event_incident_report'] . ' HOUR) > NOW() AND c_incidents = 1) as report_allowed
			  FROM ' . EVENTS_TABLE . ', ' . EVENTDATES_TABLE .  ', ' . CHAMPIONSHIPS_TABLE . ' 
			  WHERE ed_event = e_id AND e_championship = c_id AND ed_division = ' . $division_id . ' AND e_id = ' . $event_id;
		$res = $db->sql_query($q);
		if ($row = $db->sql_fetchrow($res))
		{
			$champ_id = $row['e_championship'];
			if($row['report_allowed'])
			{
				$this->incident = '<a href="usercp.php?action=createincident&event=' . $event_id . 
								  '&division='. $division_id .'&race='. $race_id .'">' . $lang['IncidentAdd'] . '</a>';
			}
			
		}
		else
		{
			die('DB Error');
		}
		
		//calculate replay file
		
		global $properties;

                $this->replay = "";
		$replay = '/Results/' . $champ_id . '/' . $division_id . '/' . $event_id . '/R' . $race_id . '.vcr';
		$replay2 = '/Results/' . $champ_id . '/' . $division_id . '/' . $event_id . '/R' . $race_id . '.Vcr';
		
		if(file_exists('..' . $replay))
		{
			$this->replay = $lang['DownloadReplay'] . '<a href="' . $replay . '">' . $lang['DownloadRace'] . '</a>';
		}
		elseif(file_exists('..' . $replay2))
		{
			$this->replay = $lang['DownloadReplay'] . '<a href="' . $replay2 . '">' . $lang['DownloadRace'] . '</a>';
		}

                if($this->replay != "")
                {

                    $replay = '/Results/' . $champ_id . '/' . $division_id . '/' . $event_id . '/Q' . $race_id . '.vcr';
                    $replay2 = '/Results/' . $champ_id . '/' . $division_id . '/' . $event_id . '/Q' . $race_id . '.Vcr';

                    if(file_exists('..' . $replay))
                    {
                            $this->replay .= ', <a href="' . $replay . '">' . $lang['DownloadQualifying'] . '</a>';
                    }
                    elseif(file_exists('..' . $replay2))
                    {
                            $this->replay .= ', <a href="' . $replay2 . '">' . $lang['DownloadQualifying'] . '</a>';
                    }

                }
		
		$qR = '/Results/' . $champ_id . '/' . $division_id . '/' . $event_id . '/Q' . $race_id . '.xml';
		$q1R = '/Results/' . $champ_id . '/' . $division_id . '/' . $event_id . '/Q1.xml';
		$rR = '/Results/' . $champ_id . '/' . $division_id . '/' . $event_id . '/R' . $race_id . '.xml';
		
		if(!file_exists('..' . $qR) && file_exists('..' . $q1R))
		{
			$qR = $q1R;
		}
				
		if(file_exists('..' . $qR) && file_exists('..' . $rR))
		{
			$sep = '';
			if(isset($this->replay))
			{
				$sep = ' | ';
			}
			$this->rfreport = $sep . '<a href="http://www.vrl-simracing.be/rfactorreport/index.php?qualyfile=' .
									htmlentities($properties['root'] . $qR) . '&racefile=' .
									htmlentities($properties['root'] . $rR) . '">' . $lang['DownloadReport'] . '</a>' ;
		}
		
		$q = 'SELECT r_weight, r_qualifyingtime, r_qualifyingrank, r_racetime, r_racelaps, r_raceposition, r_dnfreason, ' .
				'r_pitstops, r_lapsled, r_fastestlap, r_fastestlap_rank, r_points, u.user_id, pf_drivername as user_drivername, es_no, '.
				'c_id, c_model, c_manufacturer, cs_imageThmb, '.
				'(SELECT t.t_id FROM ' . TEAMS_TABLE . ' t WHERE t.t_id = es_team LIMIT 0, 1) AS t_id,'.
				'(SELECT t.t_name FROM ' . TEAMS_TABLE . ' t WHERE t.t_id = es_team LIMIT 0, 1) AS t_name '. 
				' FROM ' . RACERESULTS_TABLE . ', ' . USERS_TABLE . ' u, ' . EVENTSIGNUPS_TABLE . ', '  . CARS_TABLE . ', '  . 
				CHAMPSIGNUPS_TABLE . ', ' . EVENTS_TABLE . ', ' . DRIVERNAME_TABLE . ' d ' .
				' WHERE r_event = ' . $event_id . ' AND r_race = ' . $race_id . ' AND es_division = ' . $division_id . 
				' AND u.user_id = r_driver AND es_driver = r_driver AND es_car = c_id AND es_event = r_event AND cs_driver = es_driver ' .
				' AND cs_champ = e_championship AND es_event = e_id AND u.user_id = d.user_id ORDER BY ' . $filter;

		$res = $db->sql_query($q);
		while ($row = $db->sql_fetchrow($res))
		{
			if($row['r_racetime'] > 0 && $row['r_racetime']  < RACETIME_DNF)
				$row['r_racetime'] = formatTimestamp($row['r_racetime'], '%H:%M:%S');
			else
				$row['r_racetime'] = $lang['ResultsDNF'];
			if($row['r_raceposition'] == 255)
			{
				$row['r_raceposition'] = '';
			}
			
			if($row['r_fastestlap'] > 0 && $row['r_fastestlap']  < RACETIME_DNF)
				$row['r_fastestlap'] = formatTimestamp($row['r_fastestlap'], '%M:%S');
			else
				$row['r_fastestlap'] = '';
			
			
			if($row['r_qualifyingtime'] > 0 && $row['r_qualifyingtime']  < RACETIME_DNF)
				$row['r_qualifyingtime'] = formatTimestamp($row['r_qualifyingtime'], '%M:%S');
			else
				$row['r_qualifyingtime'] = '';
			
			$this->records[] = $row;
		}
		
	}
	
	function render()
	{
		global $lang, $skin_dir, $image_dir;
		$url = $this->url;
		$links = $this->replay . $this->rfreport;
		$links = $links == '' ? $this->incident : $this->incident . ($this->incident == '' ? '' : ' | ') . $links;
		include $skin_dir . 'tpl/tableStart.tpl';
		include $skin_dir . 'tpl/resultsHeader.tpl';
		$on = false;
		foreach($this->records as $data)
		{
			$mode = $on ? 'On' : 'Off';
			if($data['r_fastestlap_rank'] == 1)
				$data['r_fastestlap'] = '<b>' . $data['r_fastestlap'] . '</b>';
				
			if($data['r_qualifyingrank'] == 1)
				$data['r_qualifyingtime'] = '<b>' . $data['r_qualifyingtime'] . '</b>';
				
			if($data['r_raceposition'] == 1)
				$data['r_racetime'] = '<b>' . $data['r_racetime'] . '</b>';
				
			$driverinfo = $data['cs_imageThmb'] != '' ? '<p align=&quot;center&quot;><img src=&quot;' . $image_dir . 
												$data['cs_imageThmb'] . '&quot;/><br>': '<p align=&quot;center&quot;>' ;
			$driverinfo .= $data['es_no'] == 0 ? $data['user_drivername'] . '<br>' : $data['es_no'] . ' ' . $data['user_drivername'] . '<br>';
			$driverinfo .= $data['t_id'] > 0 ? '<a href=&quot;teams.php?id=' . $data['t_id'] . '&quot;>'. $data['t_name']. '</a>': $lang['Independent'];
			$driverinfo .= '<br><a href=&quot;cars.php?id=' . $data['c_id'] . '&quot;>' . $data['c_manufacturer'] . ' '  .  $data['c_model'] . '</a>';
			$driverinfo .= '</p>';
			
			$data['user_drivername'] = '<a href="drivers.php?id=' . $data['user_id'] . '" onmouseover="Tip(\'' . $driverinfo . 
						'\', BGCOLOR, \'#FFFFFF\', BORDERCOLOR, \'#000000\', STICKY, true, FADEIN, 500, FADEOUT, 500)" onmouseout="UnTip()">' . 
						$data['user_drivername'] . '</a>';
				
			include $skin_dir . 'tpl/resultsEntry.tpl';
			$on = !$on;
		}
		
		include $skin_dir . 'tpl/tableEnd.tpl';
		
	}
	
}

class rally_results
{
	var $records = Array();
        var $stagecount = 0;
	var $url, $replay, $rfreport, $incident;

	function rally_results($event_id, $division_id, $url)
	{
		global $db, $lang, $properties;
		$champ_id = 0;
		if(substr($url,0,1) == 'e')
			$this->url = $url . '&race=' . $division_id . "-1";
		else
			$this->url = $url . '&race=' . $event_id . '-'. $division_id . "-1";

		include_once('includes/page_header.php');

		$q = "SELECT e_championship, COUNT(DISTINCT rs_stage) as stage_count,
					 (DATE_ADD(ed_resultsPosted, INTERVAL {$properties['event_incident_report']} HOUR) > NOW() AND c_incidents = 1) as report_allowed
			  FROM " . EVENTS_TABLE . ", " . EVENTDATES_TABLE .  ", " . CHAMPIONSHIPS_TABLE . ", " . STAGERESULTS_TABLE . "
			  WHERE ed_event = e_id AND e_championship = c_id AND ed_division = {$division_id} AND e_id = {$event_id} AND rs_event = {$event_id}";

		$res = $db->sql_query($q);
		if ($row = $db->sql_fetchrow($res))
		{
			$champ_id = $row['e_championship'];
                        $this->stagecount = $row['stage_count'];
			if($row['report_allowed'])
			{
				$this->incident = '<a href="usercp.php?action=createincident&event=' . $event_id .
								  '&division='. $division_id .'&race=1">' . $lang['IncidentAdd'] . '</a>';
			}

		}
		else
		{
			die('DB Error');
		}


		$filter = '';
		if(isset($_GET['order']))
		{
			if($_GET['order'] > 1 && $_GET['order'] <= $this->stagecount + 1 )
			{
				$filter = "ss" . ($_GET['order'] - 1) . "_position ASC";
                        }
			else
			{
				$filter = 'r_raceposition ASC';
			}
		}
		else
		{
			$filter = 'r_raceposition ASC';
		}

		//calculate replay file

		global $properties;
                $this->replay = $lang['DownloadReplay'];

                $query_select = "";
                $query_from = "";
                $query_where = "";

                for($x = 1; $x <= $this->stagecount; $x++)
                {
                    $query_select .= "ss{$x}.rs_time as ss{$x}_time, IFNULL(ss{$x}.rs_position,".RACEPOS_DNF.") as ss{$x}_position, ";
                    $query_from .= " LEFT JOIN (SELECT * FROM lc_rallystageresults where rs_stage = {$x}) ss{$x} ON (ss{$x}.rs_driver = r_driver and ss{$x}.rs_event = r_event) ";
                    

                    $replay = '/Results/' . $champ_id . '/' . $division_id . '/' . $event_id . '/SS' . $x . '.vcr';
                    $replay2 = '/Results/' . $champ_id . '/' . $division_id . '/' . $event_id . '/SS' . $x . '.Vcr';

                    if(file_exists('..' . $replay))
                    {
                            $this->replay .= '<a href="' . $replay . '">SS' . $x . '</a> | ';
                    }
                    elseif(file_exists('..' . $replay2))
                    {
                            $this->replay .= '<a href="' . $replay2 . '">SS' . $x . '</a> | ';
                    }
                }

                if(substr($this->replay,-2)=="| ");
                    $this->replay = substr($this->replay, 0 , -2);


		$q = "SELECT r_racetime, r_raceposition, r_dnfreason, r_points, u.user_id, pf_drivername as user_drivername, es_no,
				c_id, c_model, c_manufacturer, cs_imageThmb, {$query_select}
				(SELECT t.t_id FROM " . TEAMS_TABLE . " t WHERE t.t_id = es_team LIMIT 0, 1) AS t_id,
				(SELECT t.t_name FROM " . TEAMS_TABLE . " t WHERE t.t_id = es_team LIMIT 0, 1) AS t_name
				 FROM " . USERS_TABLE . " u, " . EVENTSIGNUPS_TABLE . ", "  . CARS_TABLE . ", ".
				CHAMPSIGNUPS_TABLE . ", " . EVENTS_TABLE . ", " . DRIVERNAME_TABLE . " d, " . RACERESULTS_TABLE . " {$query_from}
				 WHERE r_event = {$event_id} AND es_division = {$division_id}
				 AND u.user_id = r_driver AND es_driver = r_driver AND es_car = c_id AND es_event = r_event AND cs_driver = es_driver 
				 AND cs_champ = e_championship AND es_event = e_id AND u.user_id = d.user_id ORDER BY {$filter}";

                $res = $db->sql_query($q);
		while ($row = $db->sql_fetchrow($res))
		{
			if($row['r_racetime'] > 0 && $row['r_racetime']  < RACETIME_DNF)
				$row['r_racetime'] = formatTimestamp($row['r_racetime'], '%H:%M:%S');
			else
				$row['r_racetime'] = $lang['ResultsDNF'];
			if($row['r_raceposition'] == 255)
			{
				$row['r_raceposition'] = '';
			}

                        for($x = 1; $x <= $this->stagecount; $x++)
                        {
                            if($row["ss{$x}_position"] == RACEPOS_DNF)
                            {
                                    $row["ss{$x}_time"] = $lang['ResultsDNF'];
                            }
                            else
                            {
                                if($row["ss{$x}_time"] > 0 && $row["ss{$x}_time"]  < RACETIME_DNF)
                                    $row["ss{$x}_time"] = formatTimestamp($row["ss{$x}_time"], '%M:%S');
                                else
                                    $row["ss{$x}_time"] = $lang["ResultsDNF"];
                            }
                        }
			$this->records[] = $row;
		}

	}

	function render()
	{
		global $lang, $skin_dir, $image_dir;
		$url = $this->url;
		$links = $this->replay . $this->rfreport;
		$links = $links == '' ? $this->incident : $this->incident . ($this->incident == '' ? '' : ' | ') . $links;

                $col_count = 4 + $this->stagecount;
		include $skin_dir . 'tpl/tableStart.tpl';

                //replay row
		include $skin_dir . 'tpl/rowStart.tpl';
                $class = "tableHeading";
                $width = "colspan=\"{$col_count}\"";
                $value = $links;
		include $skin_dir . 'tpl/tableCell.tpl';
		include $skin_dir . 'tpl/rowEnd.tpl';
                $width="";
                
                //header for results
		include $skin_dir . 'tpl/rowStart.tpl';
                $value = "<a href='{$url}&order=1'>{$lang['ResultsPos']}</a>";
		include $skin_dir . 'tpl/tableCell.tpl';
                $value = "";
		include $skin_dir . 'tpl/tableCell.tpl';
                for($x = 1; $x <= $this->stagecount; $x++)
                {
                    $order = $x + 1;
                    $value = "<a href='{$url}&order={$order}'>SS{$x}</a>";
                    include $skin_dir . 'tpl/tableCell.tpl';
                }
                $value = "<a href='{$url}&order=1'>{$lang['ResultsTime']}</a>";
		include $skin_dir . 'tpl/tableCell.tpl';
                $value = "<a href='{$url}&order=1'>{$lang['ResultsPts']}</a>";
		include $skin_dir . 'tpl/tableCell.tpl';
		include $skin_dir . 'tpl/rowEnd.tpl';


		$on = false;
		foreach($this->records as $data)
		{
			$mode = $on ? 'On' : 'Off';
			if($data['r_raceposition'] == 1)
				$data['r_racetime'] = '<b>' . $data['r_racetime'] . '</b>';


			$driverinfo = $data['cs_imageThmb'] != '' ? '<p align=&quot;center&quot;><img src=&quot;' . $image_dir .
												$data['cs_imageThmb'] . '&quot;/><br>': '<p align=&quot;center&quot;>' ;
			$driverinfo .= $data['es_no'] == 0 ? $data['user_drivername'] . '<br>' : $data['es_no'] . ' ' . $data['user_drivername'] . '<br>';
			$driverinfo .= $data['t_id'] > 0 ? '<a href=&quot;teams.php?id=' . $data['t_id'] . '&quot;>'. $data['t_name']. '</a>': $lang['Independent'];
			$driverinfo .= '<br><a href=&quot;cars.php?id=' . $data['c_id'] . '&quot;>' . $data['c_manufacturer'] . ' '  .  $data['c_model'] . '</a>';
			$driverinfo .= '</p>';

			$data['user_drivername'] = '<a href="drivers.php?id=' . $data['user_id'] . '" onmouseover="Tip(\'' . $driverinfo .
						'\', BGCOLOR, \'#FFFFFF\', BORDERCOLOR, \'#000000\', STICKY, true, FADEIN, 500, FADEOUT, 500)" onmouseout="UnTip()">' .
						$data['user_drivername'] . '</a>';

			
                        include $skin_dir . 'tpl/rowStart.tpl';

                        $class="tableEntryNum{$mode}";
                        $value=$data['r_raceposition'];
                        include $skin_dir . 'tpl/tableCell.tpl';

                        $class="tableEntryText{$mode}";
                        $value=$data['user_drivername'];
                        include $skin_dir . 'tpl/tableCell.tpl';

                        $class="tableEntryNum{$mode}";
                        for($x = 1; $x <= $this->stagecount; $x++)
                        {
                            if($data["ss{$x}_position"] == 1)
                                $value =  '<b>' . $data["ss{$x}_time"] . '</b>';
                            else
                                $value =  $data["ss{$x}_time"];
                            include $skin_dir . 'tpl/tableCell.tpl';
                        }

                        $value=$data['r_racetime'];
                        include $skin_dir . 'tpl/tableCell.tpl';

                        $value=$data['r_points'];
                        include $skin_dir . 'tpl/tableCell.tpl';

                        include $skin_dir . 'tpl/rowEnd.tpl';
			$on = !$on;
		}

		include $skin_dir . 'tpl/tableEnd.tpl';

	}

}
?>